﻿
using WebServer;
/// <summary>
/// 查找用户在哪个数据库
/// </summary>
public class NetHandler_FindUserDatabase : NetMessageHandler
{
    public const string key = "FindUserDatabase";

    public static NetHandler_FindUserDatabase NewHandler()
    {
        return new NetHandler_FindUserDatabase();
    }


    protected override ISerialize NewData() => new FindUserDatabaseData();

    public override void Execute(Remote TCPRemote, ISerialize data)
    {
        FindUserDatabaseData findUserData = data as FindUserDatabaseData;

        GameDebug.Log($"{findUserData.username} 请求查询所在数据库");

        FindUserResponseData responseData = new FindUserResponseData();

        WebServerController.Instance.FindUserDatabase(findUserData.username,(resServer) => 
        {
            GameDebug.Log($"查找用户完毕：{resServer?.host} ");
            if(resServer != null)
            {
                responseData.host = resServer.host;
            }
            this.SendResponse(TCPRemote, key, this.m_MessageReceived.seq, responseData.Write());
        });

    }
}

